﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Web.Services;


namespace DEMO_TEMP1
{
    public partial class Login : Form
    {
        public Login()
        {
            InitializeComponent();
           // textBox1.Size =new  System.Drawing.Size(120, 80);
            DEMO_TEMP1.MainMenu menu = new DEMO_TEMP1.MainMenu( false ,0);
            menu.Close();
        }

        private void menuItem1_Click(object sender, EventArgs e)
        {

            this.Dispose();
            MainMenu main = new MainMenu(false,0);
            main.Show();
           
        }
        DataSet ds = new DataSet();
        DataSet dsSystemParms = new DataSet();
        DataSet dsResolurces = new DataSet();
        bool chlogin;
        string A = String.Empty;
        private void menuItem2_Click(object sender, EventArgs e)
        {
            //pictureBox2.Visible = true;
            //pictureBox2.Show();
            
            string id = textBox1.Text;
            string pass = textBox2.Text;
            //localhost.Service1 con = new localhost.Service1();
           Demo_HHT_EARTH.WebPor.Service1 con = new Demo_HHT_EARTH.WebPor.Service1();
            //Demo_HHT_EARTH.WebPor.Service1 
            con.Url = string.Format("http://192.168.1.220/WebAppPor01/Service1.asmx");
            //chlogin = con.Conect(id,pass );
           // chlogin = con.Connect_CallSto(id, pass);
            try
            {

                chlogin = con.InformationConection();
            }
            catch (Exception)
            {

                chlogin = false;
            }
          
            
            if (chlogin)
            {
       
                
                ds = con.CallStoReal(id, pass, "EICS HHT", "MY PDA", "YES", "1.0");
                if (ds == null)
                {

                    chlogin = false;
                }
                else
                {
                    A = ds.Tables[0].Rows[0]["Column1"].ToString();
                    if (A.Equals("PASS"))
                    {
                        chlogin = true;
                        Demo_HHT_EARTH.GobalVariableEARTH.ApplicationID = "EARTHHHT";
                        Demo_HHT_EARTH.GobalVariableEARTH.UserDevice = "MY PDA";
                        Demo_HHT_EARTH.GobalVariableEARTH.UserID = id;
                    }
                    else if (A.Equals("WARNING"))
                    {
                        chlogin = false;
                    }
                    else
                    {
                        chlogin = false;
                    }
                }
                if (chlogin)
                {
                   // this.Close();
                    dsSystemParms = con.usp_LoadSystemParms("EARTHHHT", null, "ERP", "My PC");//question
                    if (dsSystemParms != null )
                    {
                        if (dsSystemParms.Tables[0].Rows[0]["Status"].ToString() == "PASS")
	                    {
                            dsResolurces = con.usp_LoadResources("EARTHHHT",1033, "WARNING-0002", "ERP", "My PC");//question
                            if (dsResolurces  != null)
                            {
                                if (dsResolurces.Tables[0].Rows[0]["Status"].ToString() == "PASS")
                                {
                                    MainMenu menu = new MainMenu(chlogin, 1);
                                    menu.Show();
                                }
                                else
                                {
                                    label3.Visible = true;
                                    label3.Enabled = true;
                                    label3.Text = "Resolurces Not PASS";
                                }
                            }

                            else
                            {
                                label3.Visible = true;
                                label3.Enabled = true;
                                label3.Text = "Resolurces Not DATA";
                            }
	                    }
                        else
                        {
                            label3.Visible = true;
                            label3.Enabled = true;
                            label3.Text = "SystemParameter Not PASS";
                        }
                    }
                    else
                    {
                        label3.Visible = true;
                        label3.Enabled = true;
                        label3.Text = "SystemParameter Not DATA";
                    }
                    
                    


                }
                else
                {
                    if (A.Equals("WARNING"))
                    {
                        label3.Visible = true;
                        label3.Enabled = true;
                        label3.Text = ds.Tables[0].Rows[0]["Column3"].ToString();
                        chlogin = true;
                    }
                    else
                    {
                        label3.Visible = true;
                        label3.Enabled = true;
                        label3.Text = ds.Tables[0].Rows[0]["Column3"].ToString();
                    }

                    
                }
            
            }
            else
            {
               
                label3.Visible = true;
                label3.Text = "Network ERROR";
            }
           

           
            
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void label3_ParentChanged(object sender, EventArgs e)
        {

        }

        private void Login_Load(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
           // pictureBox2.Visible = true;
           // pictureBox2.Show();
            //pictureBox2.Image = new Bitmap("C:\\Users\\Administrator\\Desktop\\icon\\ajax_loader_blue_32.gif");
            string id = textBox1.Text;
            string pass = textBox2.Text;
            //localhost.Service1 con = new localhost.Service1();
            Demo_HHT_EARTH.WebPor.Service1 con = new Demo_HHT_EARTH.WebPor.Service1();
            //Demo_HHT_EARTH.WebPor.Service1 
            con.Url = string.Format("http://192.168.1.220/WebAppPor01/Service1.asmx");
            //chlogin = con.Conect(id,pass );
            // chlogin = con.Connect_CallSto(id, pass);
            
            //pictureBox2.Enabled = true;

            try
            {

                chlogin = con.InformationConection();
            }
            catch (Exception)
            {

                chlogin = false;
            }


            if (chlogin)
            {


                ds = con.CallStoReal(id, pass, "EICS HHT", "MY PDA", "YES", "1.0");
                if (ds == null)
                {

                    chlogin = false;
                }
                else
                {
                    A = ds.Tables[0].Rows[0]["Column1"].ToString();
                    if (A.Equals("PASS"))
                    {
                        chlogin = true;
                        Demo_HHT_EARTH.GobalVariableEARTH.ApplicationID = "EARTHHHT";
                        Demo_HHT_EARTH.GobalVariableEARTH.UserDevice = "MY PDA";
                        Demo_HHT_EARTH.GobalVariableEARTH.UserID = id;
                    }
                    else if (A.Equals("WARNING"))
                    {
                        chlogin = false;
                    }
                    else
                    {
                        chlogin = false;
                    }
                }
                if (chlogin)
                {
                    // this.Close();
                    dsSystemParms = con.usp_LoadSystemParms("EARTHHHT", null, "ERP", "My PC");//question
                    if (dsSystemParms != null)
                    {
                        if (dsSystemParms.Tables[0].Rows[0]["Status"].ToString() == "PASS")
                        {
                            dsResolurces = con.usp_LoadResources("EARTHHHT", 1033, "WARNING-0002", "ERP", "My PC");//question
                            if (dsResolurces != null)
                            {
                                if (dsResolurces.Tables[0].Rows[0]["Status"].ToString() == "PASS")
                                {
                                    //pictureBox2.Visible = false;
                                    //pictureBox2.Enabled = false;
                                    MainMenu menu = new MainMenu(chlogin, 1);
                                    menu.Show();
                                }
                                else
                                {
                                    label3.Visible = true;
                                    label3.Enabled = true;
                                    label3.Text = "Resolurces Not PASS";
                                }
                            }

                            else
                            {
                                label3.Visible = true;
                                label3.Enabled = true;
                                label3.Text = "Resolurces Not DATA";
                            }
                        }
                        else
                        {
                            label3.Visible = true;
                            label3.Enabled = true;
                            label3.Text = "SystemParameter Not PASS";
                        }
                    }
                    else
                    {
                        label3.Visible = true;
                        label3.Enabled = true;
                        label3.Text = "SystemParameter Not DATA";
                    }




                }
                else
                {
                    if (A.Equals("WARNING"))
                    {
                        label3.Visible = true;
                        label3.Enabled = true;
                        label3.Text = ds.Tables[0].Rows[0]["Column3"].ToString();
                        chlogin = true;
                    }
                    else
                    {
                        label3.Visible = true;
                        label3.Enabled = true;
                        label3.Text = ds.Tables[0].Rows[0]["Column3"].ToString();
                    }


                }

            }
            else
            {

                label3.Visible = true;
                label3.Text = "Network ERROR";
            }
           

        }

    }
}